var express = require("express");
var router = express.Router();
const Result = require("../../utils/result");
const topicCategoryServices = require("../services/topicCategory");

//添加分类
router.post('/category',async function (req, res){
    const {category} = req.body;
    await topicCategoryServices.addCategory(category);
    res.json(Result.success());
});


//更新一个分类
router.put('/category/:id',async function (req, res){
    const id = req.params.id;
    const category = req.body.category;
    await topicCategoryServices.updateCategory(id,category);
    res.json(Result.success());
});

//删除一个分类
router.delete('/category/:id',async function (req, res){
    const id = req.params.id;
    await topicCategoryServices.deleteCategory(id);
    res.json(Result.success());
});

//获取分类列表
router.get('/getList',async function (req, res){
    const topicData = await topicCategoryServices.getCategoryList();
    res.json(Result.success({topicData}));
})

module.exports = router;